package com.physics.mps.module.task.sub;

import com.physics.mps.entity.vo.ResponseResult;
import com.physics.mps.module.compute.TaskComputeResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author mcsoft
 * @date 2023/10/17 19:50
 **/
@Api(tags = "任务中心-子任务结果")
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/taskComputeResult")
public class TaskComputeResultController {

    private final TaskComputeResultService taskComputeResultService;

    @ApiOperation(value = "获取结果图片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true),
            @ApiImplicitParam(paramType = "path", name = "id", value = "taskComputeResultId", dataType = "String", required = true)
    })
    @PostMapping("/getResultPic/{id}")
    public ResponseResult getResultPic(@PathVariable("id") String id) throws IOException {
        return ResponseResult.success(taskComputeResultService.getResultPic(id));
    }

    @PostMapping("/getErrorTaskResult/{id}")
    public ResponseResult getErrorTaskResult(@PathVariable("id") String id) throws IOException {
        return ResponseResult.success(taskComputeResultService.getErrorTaskResult(id));
    }

    @ApiOperation(value = "下载结果odb文件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @GetMapping(value = "/downloadOdb/{id}")
    public void downloadOdb(HttpServletResponse response, @PathVariable("id") String id) {
        taskComputeResultService.downloadFolder(response, id);
    }

    @ApiOperation(value = "下载结果odb文件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @GetMapping(value = "/downloadOdb2/{id}")
    public void downloadOdb2(HttpServletResponse response, @PathVariable("id") String id) {
        String local = "C:\\Users\\" + System.getProperty("user.name") + "\\Downloads\\";
        taskComputeResultService.downloadFolder(response, id, local);
    }
}
